package com.mspbots.sync.wise.controller;

import com.mspbots.sync.callback.params.CallbackParam;
import com.mspbots.sync.wise.service.CallbackService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.validation.Valid;

/**
 * com.mspbots.sync.callback.CallBackController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/10/9
 */
@Log4j2
@RestController
@RequiredArgsConstructor
@RequestMapping("callbacks")
public class CallBackController {

    private final CallbackService service;

    @GetMapping("{tenant}")
    public Mono<Object> getCallbacks(@PathVariable Integer tenant) {
        return this.service.getCallbacks(tenant);
    }

    @PutMapping("{tenant}/{id}")
    public Mono<Object> putCallbacks(@PathVariable Integer tenant, @PathVariable int id,
                                     @Valid @RequestBody CallbackParam body) {
        return this.service.putCallbacks(tenant, id, body);
    }

    @PostMapping("{tenant}")
    public Mono<Object> postCallbacks(@PathVariable Integer tenant, @Valid @RequestBody CallbackParam body) {
        return this.service.postCallbacks(tenant, body);
    }

    @DeleteMapping("{tenant}/{id}")
    public Mono<Object> deleteCallbacks(@PathVariable Integer tenant, @PathVariable int id) {
        return this.service.deleteCallbacks(tenant, id);
    }
}
